﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace BluePortal.Encoding.Core.Configuration
{
    public class StreamServiceSettings : ConfigurationElement
    {
        // Fields
        private static readonly ConfigurationProperty _propStreamService = new ConfigurationProperty("streamService", typeof(string), "", ConfigurationPropertyOptions.IsRequired);
        private static ConfigurationPropertyCollection _properties = new ConfigurationPropertyCollection();
        private static readonly ConfigurationProperty _propName = new ConfigurationProperty("name", typeof(string), null, null, null, ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
        private static readonly ConfigurationProperty _propParameters = new ConfigurationProperty("parameters", typeof(string), string.Empty, ConfigurationPropertyOptions.None);

        // Methods
        static StreamServiceSettings()
        {
            _properties.Add(_propName);
            _properties.Add(_propStreamService);
            _properties.Add(_propParameters);
        }

        public StreamServiceSettings()
        {
        }

        public StreamServiceSettings(string name, string connectionString) : this()
        {
            this.Name = name;
            this.StreamService = connectionString;
        }

        public StreamServiceSettings(string name, string streamService, string parameters) : this()
        {
            this.Name = name;
            this.StreamService = streamService;
            this.Parameters = parameters;
        }

        public override string ToString()
        {
            return this.StreamService;
        }

        // Properties
        [ConfigurationProperty("streamService", Options=ConfigurationPropertyOptions.IsRequired, DefaultValue="")]
        public string StreamService
        {
            get
            {
                return (string) base[_propStreamService];
            }
            set
            {
                base[_propStreamService] = value;
            }
        }

        internal string Key
        {
            get
            {
                return this.Name;
            }
        }

        [ConfigurationProperty("name", Options=ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired, DefaultValue="")]
        public string Name
        {
            get
            {
                return (string) base[_propName];
            }
            set
            {
                base[_propName] = value;
            }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get
            {
                return _properties;
            }
        }

        [ConfigurationProperty("parameters", DefaultValue = "")]
        public string Parameters
        {
            get
            {
                return (string) base[_propParameters];
            }
            set
            {
                base[_propParameters] = value;
            }
        }
    }
}
